package com.dragon.client.controller.customer;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dragon.common.model.Insert;
import com.dragon.common.model.ResponseData;
import com.dragon.common.model.Update;
import com.dragon.logical.service.customer.ITechnicalPersonService;
import com.dragon.repository.domain.dto.TechnicalPersonDTO;
import com.dragon.repository.domain.vo.TechnicalPersonVO;
import com.dragon.repository.entity.TechnicalPerson;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 技术联系人表 前端控制器
 * </p>
 *
 * @author sy
 * @since 2023-07-05
 */
@RestController
@RequestMapping("technicalPerson")
@Api(tags = "技术联系人")
public class TechnicalPersonController {

    @Autowired
    ITechnicalPersonService service;

    @GetMapping("list")
    @ApiOperation("获取技术联系人列表")
    public ResponseData<List<TechnicalPersonDTO>> technicalList(){
        Page<TechnicalPerson> technical = service.technicalList();
        return ResponseData.success(TechnicalPersonDTO.convertList(technical.getRecords()));
    }

    @PostMapping("add")
    @ApiOperation("新增技术联系人")
    public ResponseData addTechnical(@RequestBody @Validated(Insert.class) TechnicalPersonVO vo) {
        service.addTechnical(TechnicalPersonVO.convert(vo));
        return ResponseData.success();
    }

    @PostMapping("update")
    @ApiOperation("更新技术联系人")
    public ResponseData updateTechnical(@RequestBody @Validated(Update.class) TechnicalPersonVO vo ){
        service.updateTechnical(TechnicalPersonVO.convert(vo));
        return ResponseData.success();
    }

    @PostMapping("delete")
    @ApiOperation("删除技术联系人")
    public ResponseData deleteTechnical( @ApiParam(name = "id",value = "技术联系人id", required = true, type = "int") @RequestParam Integer id){
        service.deleteTechnical(id);
        return ResponseData.success();
    }

}
